package com.zmn.plat.services.impl.extension.category;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.extension.category.ExtensionCategory;
import com.zmn.plat.model.entity.extension.category.ExtensionCategoryQuery;
import com.zmn.plat.persistence.interfaces.extension.category.ExtensionCategoryDao;
import com.zmn.plat.services.interfaces.extension.category.ExtensionCategoryService;

@Service
public class ExtensionCategoryServiceImpl implements ExtensionCategoryService {

    @Resource
    ExtensionCategoryDao extensionCategoryDao;

    @Override
    public ExtensionCategory findByKey(Integer categId) {
        return extensionCategoryDao.findByKey(categId);
    }

    @Override
    public ExtensionCategory findByName(String name) {
        return extensionCategoryDao.findByName(name);
    }

    @Override
    public List<ExtensionCategory> listPageByQuery(ExtensionCategoryQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return extensionCategoryDao.listPageByQuery(query);
    }

    @Override
    public List<ExtensionCategory> listByQuery(ExtensionCategoryQuery query) {
        return extensionCategoryDao.listByQuery(query);
    }

    @Override
    public List<ExtensionCategory> listAll() {
        return extensionCategoryDao.listAll();
    }

    @Override
    public Integer countByQuery(ExtensionCategoryQuery query) {
        return extensionCategoryDao.countByQuery(query);
    }

    @Override
    public Integer updateStatusByKey(ExtensionCategory extensionCategory) {
        return extensionCategoryDao.updateStatusByKey(extensionCategory);
    }

    @Override
    public Integer updateStatusBatchByKey(List<Integer> ids, Integer status, String mcStaffName) {
        return extensionCategoryDao.updateBatchStatusByKey(ids, status, mcStaffName);
    }

    @Override
    public Integer updateFirstLetterByKey(Integer categId, String firstLetter, String mcStaffRealName) {
        ExtensionCategory extensionCategory = new ExtensionCategory();
        extensionCategory.setCategId(categId);
        extensionCategory.setFirstLetter(firstLetter);
        extensionCategory.setUpdater(mcStaffRealName);
        extensionCategory.setUpdateTime(new Date());
        return extensionCategoryDao.updateFirstLetterByKey(extensionCategory);
    }

    @Override
    public Integer updateSortByKey(ExtensionCategory extensionCategory) {
        return extensionCategoryDao.updateSortByKey(extensionCategory);
    }

    @Override
    public Integer updateSortByKey(Integer categId, Integer sort, String mcStaffName) {
        ExtensionCategory extensionCategory = new ExtensionCategory();
        extensionCategory.setCategId(categId);
        extensionCategory.setSort(sort);
        extensionCategory.setUpdater(mcStaffName);
        extensionCategory.setUpdateTime(DateUtil.getNow());
        return updateSortByKey(extensionCategory);
    }

    @Override
    public Integer updateByKey(ExtensionCategory extensionCategory) {
        return extensionCategoryDao.updateByKey(extensionCategory);
    }

    @Override
    public Integer insert(ExtensionCategory extensionCategory) {
        return extensionCategoryDao.insert(extensionCategory);
    }

    @Override
    public Integer deleteByKey(Integer categId) {
        return extensionCategoryDao.deleteByKey(categId);
    }

}